const list = [
  {
    key: 1,
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    description: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',
  },
  {
    key: 2,
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    description: 'My name is Jim Green, I am 42 years old, living in London No. 1 Lake Park.',
  },
  {
    key: 3,
    name: 'John',
    age: 23,
    address: 'London No. 1 Lake Park',
    description: 'My name is Jim Green, I am 42 years old, living in London No. 1 Lake Park.',
  },
  {
    key: 4,
    name: 'Joe Black',
    age: 18,
    address: 'Sidney No. 1 Lake Park',
    description: 'My name is Joe Black, I am 32 years old, living in Sidney No. 1 Lake Park.',
  },
];

export default {
  'GET /api/multiple-sorter-table': (req: any, res: any) => {
    const { sortname, sortorder } = req.query;
    if (sortorder) {
      return res.send(
        list.sort((a: any, b: any) => {
          if (a[sortname] > b[sortname]) {
            return sortorder === 'asc' ? 1 : -1;
          } else {
            return sortorder === 'asc' ? -1 : 1;
          }
        })
      );
    } else {
      return res.send(list);
    }
  },
};
